package cn.year9;

public class Message {

    private String Message;
    private String prefix;

    public String getMessage() {
        return Message;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setMessage(String message) {
        Message = message;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public void send(MessageType messageType ,String message)
   {
       switch (messageType)
       {
           case Info:
               if (prefix == null)
               {
                   this.setPrefix("信息");
               }
               printSingleColor("",36,1,"["+prefix+"]"+message);
               prefix=null;
               //System.out.println("["+prefix+"]"+message);
               break;
           case Error:
               if (prefix == null)
               {
                   this.setPrefix("错误");
               }
               printSingleColor("",31,1,"["+prefix+"]"+message);
               prefix=null;
               //System.err.println("[错误]["+prefix+"]"+message);
               break;
           case Warning:
               if (prefix == null)
               {
                   this.setPrefix("警告");
               }
               printSingleColor("",35,1,"["+prefix+"]"+message);
               //System.out.println("["+prefix+"]"+"["+messageType+"]"+message);
               prefix=null;
               break;
           default:
               System.out.println("["+prefix+"]"+message);
               prefix=null;
               break;
       }

   }

   /*
   * @param message 向控制台输出信息
   * @param is_Linefeed 决定是否换行,0为不换行
   * */
   public void print(String message,Integer is_Linefeed)
   {
       if (is_Linefeed == 0)
       {
           System.out.print(message);
       }else{
           System.out.println(message);
       }
   }

    /**
     *
     * @param pattern 前面的图案 such as "=============="
     * @param code 颜色代号：背景颜色代号(41-46)；前景色代号(31-36)
     * @param n 数字+m：1加粗；3斜体；4下划线
     * @param content 要打印的内容
     */
    public void printSingleColor(String pattern,int code,int n,String content){
        System.out.format("%s\33[%d;%dm%s", pattern, code, n, content);
    }

}
